<?php
namespace app\common\model;
use x\Xbase;
    
#鼓励奖
class Awardguli extends Xbase
{  
    public function doit($order_no){
    	$order_goods = $this->db->query("select * from order_goods_no where order_no=?",[$order_no],1);
    	if (!$order_goods) return $this->setError('没有找到订单！');
        if ($order_goods['order_total_gulijin']<0) return true;
        if (!$order_goods['gulijin_user_id']) return true;

        #下订单时记录 gulijin_user_id = s_id?s_id:last_share_id;
        
        $money = $order_goods['order_total_gulijin'];
        $fee = 0;
        $real_money = bcsub($money,$fee,2);
        if ($real_money<=0) return true;

    	$mysql = [];
    	$data = [
    		'order_no' => $this->com_order_no(),
            'order_goods_no_id' => $order_goods['id'],
    		'user_id' => $order_goods['gulijin_user_id'],
            'money' => $money,
            'fee' => $fee,
            'status' => 1,
            'note' => '获得鼓励金',
            'real_money' => $real_money,
    		'create_time' => time(),
    	];
        $mysql[] = $order_id = $this->db->insert('award_guli',$data);

        $mysql[] = m('Userbill','xcom')->doit($data['order_no'],$data['user_id'],102,'award_guli',$order_id,$data['real_money'],'money_sy','获得鼓励金');
        #服务奖
        $mysql[] = m('Awardfuwu','c')->doit($order_id,$data['user_id'],$order_goods);

        foreach($mysql as $v){if(!$v) return false;}return true;
    }
}
